<template>
  <div id="app">
    <el-row>
      <ManageHead :user="userName" :title="title" @collapse="collapse"></ManageHead>
    </el-row>
    <el-row class="h100">
      <el-col :span="isCollapse ? 1 : 3" class="h100">
        <manage-aside :user="userObj" id="aside" :isCollapse="isCollapse"></manage-aside>
      </el-col>
      <el-col :span="isCollapse ? 23 : 21" class="h100 app-main">
        <router-view :userObj="userObj" />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import ManageHead from './components/manage-head';
import ManageAside from './components/manage-aside';
import api from './api';

export default {
  components: { ManageAside, ManageHead },
  data() {
    return {
      title: '厦门钇企财富企业有限公司',
      isCollapse: false,
      fullHeight: window.innerHeight - 30,
      userName: '',
      userObj: {}
    };
  },
  mounted: function() {
    api.getCurrentUser().then((data) => {
      if (!data) {
        this.$message({
          type: 'warning',
          message: '请先登录'
        });
        if (process.env.NODE_ENV === 'production') {
          window.location.href = '/login/index';
        } else {
          window.location.href = '/login';
        }
      } else {
        this.userName = data.username;
        this.userObj = data;
        if (data.username !== 'admin' || data.root !== 1) {
          this.$router.push({
            path: '/table'
          });
        } else {
          this.$router.push({
            path: '/user'
          });
        }
      }
    });
    document.getElementById('app').style.height = this.fullHeight + 'px';
    window.addEventListener('resize', this.handleResize);
  },
  methods: {
    collapse(isCollapse) {
      this.isCollapse = isCollapse;
    },
    handleResize(event) {
      this.fullHeight = window.innerHeight - 30;
      document.getElementById('app').style.height = this.fullHeight + 'px';
      document.getElementById('aside').style.height = this.fullHeight + 'px';
    }
  }
};
</script>

<style lang="scss" scoped>
.app {
}
</style>
